<!DOCTYPE html>
<html>
<head>
    <title>修改短信模板</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script>

        var contentId = getUrlParam("contentId");
        var contentNameOrg="";
        var contentContentOrg="";

        function close(status){
            if(status=="yes"){
                window.parent.location.reload();//刷新父页面
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            }
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        }

        layui.use(['form', 'jquery', 'layer','element'], function () {
            var contentId = getUrlParam("contentId");
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var status = "yes";

            //初始化页面数据
            $(document).ready(function () {
                var url = '/xuYiContentTmp/findByContentId?contentId=' + contentId;
                $.ajax({
                    type: 'post',
                    async: false,
                    url: url,
                    success: function (json) {
                        $("#contentName").val(json.contentName);
                        $("#contentContent").val(json.contentContent);
                        contentNameOrg=json.contentName;
                        contentContentOrg=json.contentContent;
                        form.render();
                    }
                })
            });

            $('#modify').on('click', function () {
                var contentId = getUrlParam("contentId");
                var url = '/xuYiContentTmp/configureContentTemplate';
                var contentName = $.trim($("#contentName").val());
                var contentContent = $.trim($("#contentContent").val());
               if(isNull(contentName)){
                   layer.msg("请输入模板名称");
               }else if(isNull(contentContent)){
                   layer.msg("请输入模板内容");
               }else if(contentName==contentNameOrg&&contentContent==contentContentOrg){
                   layer.msg("您未做任何修改，请修改信息");
               }else{

                   if (contentName==contentNameOrg){
                       var contentNameChange = 0;
                   }else {
                       var contentNameChange = 1;
                   }
                    var param = {
                        contentId:contentId,
                        contentName:contentName,
                        contentContent: contentContent,
                        contentNameChange:contentNameChange,
                        flag: "modify"
                    };
                    $.ajax({
                        type: 'post',
                        data: param,
                        url: url,
                        success: function (data) {
                            if (data == 1) {
                                layer.confirm('操作成功，待审核', {
                                    btn: ['确认'] //按钮
                                }, function () {
                                    close(status);
                                });
                            }else if(data == 2){
                                layer.confirm('该名称已存在，请更改', {
                                    btn: ['确认'] //按钮
                                });
                            } else {
                                layer.confirm('修改失败，请重试', {
                                    btn: ['确认'] //按钮
                                });
                            }
                        },
                        error: function (data) {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    });}
            });
            $('#quit').on('click',function(){
                status="no";
                close(status);
            });
        });

    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="content-box">
            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">模板名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="contentName" lay-verify="required"
                                   autocomplete="off" class="layui-input" disabled>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-block">
                        <label class="layui-form-label">模板内容</label>
                        <div class="layui-input-block">
                            	<textarea placeholder="请输入内容" class="layui-textarea" id="contentContent"></textarea>
                        </div>
                    </div>
                </div>

                <div class="layui-block" pane=""  style="padding-left:200px;">
                    <button class="layui-btn layui-btn-normal" lay-filter="modify" id="modify">修改</button>
                    <button class="layui-btn layui-btn-normal" lay-filter="quit" id="quit">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>